import {SOURCE_URL} from "../../constant/index";

const app = getApp()
Component({
    properties: {
        cardData: {},
        count: {
            type: Number,
        }
    },
    data: {
        baseUrl: SOURCE_URL,
        flag: true,
        id: '',
    },
    methods: {
        previewImage(){
            const {image} = this.data.cardData
            wx.previewImage({
                urls:[this.data.baseUrl + image],
            })
        },
        booktime: function () {
            return this.book()
            const {cardData: data} = this.data
            this.triggerEvent('booktime', data)
        },
        toOrder(data) {
            let newdata = encodeURIComponent(JSON.stringify(data))
            const {id} = data
            const idStr = '&id=' + id
            wx.navigateTo({
                url: '/pages/book/book?newdata=' + newdata + idStr
            })
        },
        book: function () {
            if (this.data.cardData.status * 1 === 5){
                return  wx.showModal({
                    title:'维护提示',
                    content:'当前包间正在维护中,暂不可预定,请选择其他包间!'
                })
            }
            const hasMobile = app.checkHasMobile()
            if (!hasMobile) return
            const {cardData: data} = this.data
            if (data.status * 1 === 3) {
                return   wx.showModal({
                    title: '温馨提示',
                    content: '房间暂时没有打扫，您是否确定预定?',
                    cancelText: '等待保洁',
                    confirmText: '继续下单',
                    success: ev => {
                        if (ev.cancel) return
                        this.toOrder(data)
                    }
                })
            }
            this.toOrder(data)

        },
    }
})
